package com.palominocia.capa_datos_nodoCentral.dbPostgreSQL.schema2.modelo.seguridad;

import javax.persistence.Column;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.jpa.entity.RooJpaEntity;
import org.springframework.roo.addon.tostring.RooToString;

@RooJavaBean
@RooToString
@RooJpaEntity(entityName="schema2.Usuario2", schema = "capa_datos_nodo2")
@RooJpaActiveRecord(persistenceUnit = "persistenceUnitNodo")
public class Usuario2 {
	/*@Id
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "usuario_seq")
	@SequenceGenerator(name = "usuario_seq", sequenceName = "usuario_sequence", schema = "prueba", allocationSize = 1)
	@Column(name = "id")
	private Long id;*/
	/**
     */
	@NotNull
	@Column(name = "username", unique = true)
	private String username;

	/**
     */
	@NotNull
	private String password;

	/**
     */
	@NotNull
	private String email;

	/**
     */
	@NotNull
	private String habilitado;

	@Transient
	public static Usuario2 findNombreUsuario(String username) {
		Usuario2 user = null;
		try {
			user = entityManager()
					.createQuery(
							"SELECT o FROM Usuario o WHERE o.username =:username ",
							Usuario2.class).setParameter("username", username)
					.getSingleResult();
		} catch (Exception e) {
			user = null;
		}
		return user;
	}

}
